package com.parktech.sun.web.controller;

import com.parktech.sun.domain.model.industryinfo.IndustryInfo;
import com.parktech.sun.domain.model.industryprealert.IndustryPrealert;
import com.parktech.sun.domain.model.industryservice.IndustryServiceInformation;
import com.parktech.sun.domain.model.news.News;
import com.parktech.sun.domain.model.sunhz.Application;
import com.parktech.sun.domain.model.sunhz.Enterprise;
import com.parktech.sun.domain.model.unionnews.UnionNews;
import com.parktech.sun.domain.service.industryinfo.IndustryInfoService;
import com.parktech.sun.domain.service.industryprealert.IndustryPrealertService;
import com.parktech.sun.domain.service.industryservice.IndustryServiceService;
import com.parktech.sun.domain.service.news.NewsService;
import com.parktech.sun.domain.service.sunhz.ApplicationService;
import com.parktech.sun.domain.service.sunhz.EnterpriseService;
import com.parktech.sun.domain.service.unionnews.UnionNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * User: Think
 * Date: 11-1-15
 * Time: 下午4:39
 */
@Controller
@RequestMapping("/")
public class IndexController extends BaseViewController {

    @Autowired
    private NewsService newsService;

    @Autowired
    private EnterpriseService enterpriseService;

    @Autowired
    private IndustryServiceService industryServiceService;

    @Autowired
    private UnionNewsService unionNewsService;

    @Autowired
    private ApplicationService applicationService;

    @Autowired
    private IndustryPrealertService industryPrealertService;

    @Autowired
    private IndustryInfoService industryInfoService;

    public IndexController() {
    }

    @ModelAttribute("allNewsCategories")
    public Map<Integer, String> populateAllCategories() {
        Map<Integer, String> allCategories = new TreeMap<Integer, String>();
        allCategories.put(1, "行业动态");
        allCategories.put(2, "协会动态");
        allCategories.put(3, "企业动态");
        allCategories.put(4, "政府动态");
        return allCategories;
    }

    @RequestMapping
    public String index(Model model) {

        List<News> top4ImageNews = newsService.listTop4ImageNews();
        model.addAttribute("top4ImageNews", top4ImageNews);
        List<News> top7NormalNews = newsService.listTop7NormalNews();
        if (top7NormalNews.size()>0) {
            model.addAttribute("topNews", top7NormalNews.get(0));
        }
        model.addAttribute("top7NormalNews", top7NormalNews);

/*
        UnionBrief firstOrderUnionBrief = newsService.listTop4ImageNews();
        List<UnionBrief> top4UnionBrief = newsService.listTop4ImageNews();
*/
        List<Enterprise> top3Type1RecommendEnterprise = enterpriseService.listTopRecommendEnterprise(1, 6);
        model.addAttribute("top3Type1RecommendEnterprise", top3Type1RecommendEnterprise);
        List<Enterprise> top3Type2RecommendEnterprise = enterpriseService.listTopRecommendEnterprise(2, 6);
        model.addAttribute("top3Type2RecommendEnterprise", top3Type2RecommendEnterprise);
        List<Enterprise> top3Type3RecommendEnterprise = enterpriseService.listTopRecommendEnterprise(4, 6);
        model.addAttribute("top3Type3RecommendEnterprise", top3Type3RecommendEnterprise);
        List<Enterprise> top3Type4RecommendEnterprise = enterpriseService.listTopRecommendEnterprise(8, 6);
        model.addAttribute("top3Type4RecommendEnterprise", top3Type4RecommendEnterprise);
        List<Enterprise> top3Type5RecommendEnterprise = enterpriseService.listTopRecommendEnterprise(16, 6);
        model.addAttribute("top3Type5RecommendEnterprise", top3Type5RecommendEnterprise);
        List<Enterprise> top3Type6RecommendEnterprise = enterpriseService.listTopRecommendEnterprise(32, 6);
        model.addAttribute("top3Type6RecommendEnterprise", top3Type6RecommendEnterprise);

        UnionNews unionNews = unionNewsService.getTop();
        if (unionNews != null) {
            model.addAttribute(unionNewsService.getTop());
        }

        List<IndustryServiceInformation> top7PolicyInfo = industryServiceService.listTop7PolicyInfo();
        if (top7PolicyInfo.size() > 0) {
            model.addAttribute("topPolicyInfo", top7PolicyInfo.get(0));
        }
        model.addAttribute("top7PolicyInfo", top7PolicyInfo);
        List<IndustryServiceInformation> top6RequirementInfo = industryServiceService.listTop6RequirementInfo();
        model.addAttribute("top6RequirementInfo", top6RequirementInfo);

        List<IndustryPrealert> top7Prealert = industryPrealertService.listTop7Prealert();
        if (top7Prealert.size() > 0) {
            model.addAttribute("topPrealert", top7Prealert.get(0));
        }
        model.addAttribute("top7Prealert", top7Prealert);

        List<Application> top12Application = applicationService.listTop12();
        model.addAttribute("top12Application", top12Application);

        List<IndustryInfo> top6IndustryInfo = industryInfoService.listTop6();
        model.addAttribute("top6IndustryInfo", top6IndustryInfo);

        return "index";
    }
}
